<style>
    /*表头*/
    table thead {
        z-index: 2;
        position: sticky;
        position: -webkit-sticky;
        top: 0;
        background: #f4f4f4;
    }
    table thead tr th:first-child{
        position: sticky;
        top: 0;
        left: 0;
        background: #f4f4f4;
    }
    th:nth-child(2){
        position: sticky;
        left: 40px;
        background: #f4f4f4;
    }
    th:nth-child(3){
        position: sticky;
        left: 80px;
        background: #f4f4f4;
    }
    th:nth-child(4){
        position: sticky;
        left: 130px;
        background: #f4f4f4;
    }
    th:nth-child(5){
        position: sticky;
        left: 199px;
        background: #f4f4f4;
    }

    /*表格*/
    table tbody tr td:first-child {
        z-index: 1;
        position: sticky;
        position: -webkit-sticky;
        left: 0;
        background: #f4f4f4;
        box-shadow: 7px 0 5px -5px rgb(0 0 0 / 12%);
    }
    td:nth-child(2){
        position: sticky;
        left: 40px;
        background: #f4f4f4;
    }
    td:nth-child(3){
        position: sticky;
        left: 70px;
        background: #f4f4f4;
    }
    td:nth-child(4){
        position: sticky;
        left: 130px;
        background: #f4f4f4;
    }
    td:nth-child(5){
        position: sticky;
        left: 199px;
        background: #f4f4f4;
    }
</style>

<table class="table table-hover">
    <thead>
    <tr>
        @foreach($headers as $filed => $item)
        <th>{{ $item['title'] }}</th>
        @endforeach
    </tr>
    <tr style="color:#f56f9c;">
        @php
            $salesStatus = \App\Models\SalesReport\DailySv::getSalesStatus($total->avg3,$total->avg7,$total->avg15,$total->avg30);
            $avg = \App\Models\SalesReport\DailySv::getWeightAvg($total->avg3,$total->avg7,$total->avg15,$total->avg30,$salesStatus);
            $total->avg = $avg;
        @endphp
        @foreach($headers as $filed => $item)
            @if($filed == 'area')
                <td style="position: sticky; top: 0; left: 0; background: #f4f4f4;">TTL</td>
            @elseif($filed == 'avg')
                <td>{{ $avg }}</td>
            @elseif($filed == 'sales_status')
                <td>{{ \App\Models\SalesReport\DailySv::$_salesStatus[$salesStatus] }}</td>
            @elseif($filed == 'inv_factor')
                <td>{{ \App\Models\SalesReport\DailySv::getInvFactor($total) }}</td>
            @elseif($item['sumField'])
                <td>{{ $total->{$filed} ?? '' }}</td>
            @else
                <td></td>
            @endif
        @endforeach
    </tr>
    </thead>
    <tbody>
    @foreach($paginator as $row)
        <tr>
            <td>{{ $row->area->area ?? '' }}</td>
            <td>{{ $row->country->country ?? '' }}</td>
            <td>{{ \App\Util\User::getUsernameById($row->seller_id) }}</td>
            <td>{{ $row->sku->psku_code ?? '' }}</td>
            <td>{{ $row->sku->psku_cn ?? '' }}</td>
            @for($i = \App\Models\SalesReport\DailySv::V_NUM; $i >= 1; $i--)
                <td>{{ $row->{'day'.$i} }}</td>
            @endfor
            <td>{{ $row->avg3 }}</td>
            <td>{{ $row->avg7 }}</td>
            <td>{{ $row->avg15 }}</td>
            <td>{{ $row->avg30 }}</td>
            <td>{{ $row->avg }}</td>
            <td>{{ !$row->sales_status ? '' : \App\Models\SalesReport\DailySv::$_salesStatus[$row->sales_status] }}</td>
            <td>{{ $row->fba_instant_num }}</td>
            <td>{{ $row->fba_transit_num }}</td>
            <td>{{ $row->cn_instant_num }}</td>
            <td>{{ $row->cn_transit_num }}</td>
            <td>{{ $row->os_instant_num }}</td>
            <td>{{ $row->os_transit_num }}</td>
            <td>{{ \App\Models\SalesReport\DailySv::getInvFactor($row) }}</td>
        </tr>
    @endforeach
    </tbody>
</table>

{{--<script>
    if($('#fixedTd').offset().top > 0){
        setTimeout(function () {
            $("#fixedTd").css("position","absolute")
        },50);
    }
</script>--}}
